// License Notification
//======================================================
// Copyright (c) 2010 Channel Intelligence Inc.
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// which accompanies this distribution, and is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// ======================================================




using System.Collections.Generic;
using Plossum.CommandLine;
using CIP4.Common;

namespace CIP4.CMD
{
    [CommandLineManager(
        ApplicationName = CMDProgram.APPNAME,
        Description = "A commandline app",
        Copyright = "Copyright 2010 Channel Intelligence Inc")]
    class OptionsType
    {
        // plossum uses reflection to get to these variables, which the compiler can't see, so supppress never assigned warnings
#pragma warning disable 0649

        [CommandLineOption(Description = "help text",
            Aliases = "?", Prohibits = "Confirm")]
        public bool Help;

        [CommandLineOption(Description = "Action to perform, one of\n" +
            "generate - generate a serializer for the assembly given by /AssemblyFile\n" +
            "build - generate and build a serializer\n" +
            "monitor - monitor the Wrappers in use on the current machine\n" +
            "status - get status for the Wrappers in use on the current machine\n" +
            "pause - pause the Wrappers in use on the current machine\n" +
            "resume - resume (after pause) Wrappers in use on the current machine\n" +
            "cycle - force Wrappers in use on the current machine to close their providers and re-attach\n" +
            "clear - clear the state information for Wrappers on the current machine\n",
            Aliases = "a")]
        public ActionEnum Action { get; set; }

        public enum ActionEnum
        {
            None,
            Generate,
            Build,
            Monitor,
            Status,
            Stats,
            Pause,
            Resume,
            Cycle,
            Clear
        }

        [CommandLineOption(Description = "The name of the assembly containing the types to build serializers for or to monitor",
            Aliases = "af")]
        public string AssemblyFile { get; set; }

        [CommandLineOption(Description = "The name of the host machine to monitor - this has no effect on build or generate",
            Aliases = "h")]
        public string Host { get; set; }

        public List<string> TypeNameValues = new List<string>();

        [CommandLineOption(Description = "The name of a type to build a serializer for. You can specify more than one by repeated use of the /tn switch",
            Aliases = "tn", MaxOccurs = 100)]
        public void TypeName(string value)
        {
            TypeNameValues.Add(value);
        }

        public List<string> CollectionNameValues = new List<string>();

        [CommandLineOption(Description = "The name of a collection to monitor or control. You can specify more than one by repeated use of the /cn switch",
            Aliases = "cn", MaxOccurs = 100)]
        public void CollectionName(string value)
        {
            CollectionNameValues.Add(value);
        }

        [CommandLineOption(Description = "Controls the level of logging - Noise is the most verbose, Error the least - you cannot turn off errors",
            Aliases = "l")]
        public MajorEnum LoggingLevel { get; set; }

        [CommandLineOption(Description = "Displays the current options and asks for confirmation before continuing",
            Aliases = "c")]
        public bool Confirm { get; set; }

        [CommandLineOption(Description = "A qualifier added to the logfile name - allows more than one copy of the application to run at the same time",
            Aliases = "lfnq")]
        public string LogFileNameQualifier { get; set; }

#pragma warning restore 0649

        public override string ToString()
        {
            string text = string.Format("/Action {0} /LoggingLevel {1} /Host {2}{3} ", 
                Action, LoggingLevel, Host, string.IsNullOrEmpty(AssemblyFile)? string.Empty: (" /AssemblyFile " + AssemblyFile));
            foreach (string kvp in TypeNameValues)
                text += string.Format(" /TypeName \"{0}\"", kvp);
            foreach (string kvp in CollectionNameValues)
                text += string.Format(" /CollectionName \"{0}\"", kvp);
            return text;
        }
    }
}
